//HOMEWORK
//
//ATM (class)
//
//- name
//- costumers
//
//You need to be able to login with an account id and password
//You need to be able to store multiple accounts
//After any transaction you are automatically logged out
//
//Costumer (class)
//
//- First name
//- Last name
//- ID
//
//The costumer has just one account
//
//Account
//
//- ID
//- Balance
//- Password
//
//You need to be able to do a withdrawal, a deposit, check balance
//
//
//
//Create a HTML page with text page and Imput field. Do two divs; one
for text another with input text and button.
//
//Login-Menu-Seccio

//var validation = function Validation (){
//
//    var userValidation = document.getElementById("user");
//    var passwordValidation = document.getElementById("password");
//
//    if (userValidation == userArgument && passwordValidation ==
passwordArgument) {
//

//
//}





// ATM CLASS
var ATM = function (address){
	
	var _id = _generateId();
	
	var _address = address;
	
	var _costumers = {};
	
	var _generateId = function () {
		return Math.floor(Math.random()*900000000) + 100000000;
	};
	
	this.getAddress = function() {
		return _address
	};

	this.createCustomer = function(firstName, lastName) {
		var customer = new Customer(firstName, lastName);
		_costumers[customer.getId()] = customer;
	};//do a console log for showing costumer.getId
	
	this.deleteCustomer = function(customerId) {
		delete _costumers[customerId];
	};
		
	this.getCustomer = function(customerId) {
		return _costumers[customerId];
	};
	
	this.getCustomers = function() {
		return _costumers;
	};

}

var atm1 = new ATM();

// COSTUMER CLASS
var Costumer = function (firstName, lastName) {
	
	var _id = Math.floor(Math.random()*900000000) + 100000000;
	
	var _password = Math.floor(Math.random()*9000) + 1000;
	
	var _firstName = firstName;
	
	var _lastName = lastName;	
	
	var _fullName = firstName + " " + lastName;

  var _accounts = {};
  	
  this.getId() {
  	return _id;
	};

  this.getPassword() {
  	return _password;
	};

  this.createAccount = function (initialBalance) {
  	var account = new Account (initialBalance);
  	_accounts[account.getId()] = account;
  	return account.getId();
	};
	
  this.getAccount = function (accountId) {
  	return _accounts[accountId];
	};
	
}

    //ACCOUNT
    var Account = function (initialAmount) {

    //        NEW ACCOUNT

           var accountId;
  var accountIdGenerator = function AccountIdGenerator (){
                accountId = Math.floor(Math.random()*900000000) + 100000000;
                return accountId;
            }
                this.accountId = accountId;

            costumerAccounts =  costumerAccounts.push(accountId);

            var currentBalance = initialAmount;

                this.currentBalance = currentBalance;

            console.debug("Thank you Mr. %s, your account number %n
was created with an initial balance of %n euros. \nHave a nice day",
this.costumerName, this.accountId, this.currentBalance);


    //       NEW DEPOSIT


            this.deposit = function(depositAmount){

                currentBalance = currentBalance + depositAmount;
                return currentBalance; //is it necessary?
                console.debug("Now you are %n richer, bitch", depositAmount);
            };



    //       NEW WITHDRAWAL


            this.withdraw = function(withdrawAmount){

                currentBalance = currentBalance - withdrawAmount;
                return currentBalance;
                console.debug("Now you are %n more poor, bitch",
withdrawAmount);
            };



//       CHECK DEPOSIT

            this.currenBalance = function(){
                console.log("Mr. %s, your total credit is %n",
this.name, this.currentBalance );
            };
        }


    // this.costumer = costumer; //per poguer accedir a costumer desde
fora!! En serio cal??? No seria millor ferla global??





var firstAtm = new atm ("Wallstreet 890, Manhattan, NY");


console.log(firstAtm.atmId);
console.log(firstAtm.atmAdress);
console.log(firstAtm.atmCostumers);


var sergi = new firstAtm.costumer ("Sergi", "Gómez");


console.log(sergi.costumerName);
console.log(sergi.userId);
console.log(sergi.userPass);
console.log(sergi.costumerAccounts);


console.log(firstAtm.atmCostumers);

